#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Visitor {
    int age;
    char *name;
};

int main(){

    struct Visitor visitor;
    visitor.name = (char *)malloc(sizeof(char) * 100);
    // visitor.name = "init"; // malloc后再直接赋值会内存泄漏
    strcpy(visitor.name, "init");
    visitor.age = 0;

    while(strcmp(visitor.name, "n")){
        printf("输入姓名：");
        scanf("%s", visitor.name);
        if(!strcmp(visitor.name, "n")){
            break;
        }
        printf("输入年龄：");
        scanf("%d", &visitor.age);
        if(visitor.age >= 18){
            printf("%s", visitor.name);
            printf("票价20元\n");
        }
        else{
            printf("%s", visitor.name);
            printf("门票免费\n");
        }
    };
    
    
    free(visitor.name);
    return 0;
}